﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../common/jsp/taglibs.jsp"%>
<!-- 
    Copyright (C)  2011  chen wei hua.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 2.0
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU Free Documentation License".
 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>生产计划-编辑入库单</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<%@ include file="../../common/jsp/config.jsp"%>
<%@ include file="../../common/jsp/validate.jsp"%>
<%@ include file="../../common/jsp/autocomplete.jsp"%>
<script type="text/javascript" src="common/js/calendar/WdatePicker.js" ></script>
<script type="text/javascript" src="common/js/jquery/chinaArea/jquery.fillOptions.js"></script>
<script type="text/javascript">
var productNamesIndex = <s:property value="voucher.voucherDetails.size"/> - 1;
function addProduct() {
	productNamesIndex++;
	var productTable = $("#productList");
	productTable.find("tr").last().before(
	           '<tr class="odd">'
	          +'<td><input type="button" value="请选择" onclick="openSelectDialog('+productNamesIndex+')" />'
	          +'<s:hidden id="productCodes-'+productNamesIndex+'" name="productCodes" />'
	          +'<s:hidden id="productIds-'+productNamesIndex+'" name="productIds" /></td>'
	          +'<td><span id="productRootCategorys-'+productNamesIndex+'"></span>'
	          +'<s:hidden id="rootCategoryNames-'+productNamesIndex+'" name="rootCategoryNames" /></td>'
	          +'<td><span id="productCategorys-'+productNamesIndex+'"></span>'
	          +'<s:hidden id="categoryNames-'+productNamesIndex+'" name="categoryNames" /></td>'
	          +'<td><span id="productNames-'+productNamesIndex+'"></span></td>'
	          +'<td><span id="productTypes-'+productNamesIndex+'"></span></td>'
	          +'<td><span id="productSkuNames-'+productNamesIndex+'"></span>'
	          +'<s:hidden id="productSkus-'+productNamesIndex+'" name="productSkus" /></td>'
	          +'<td><span id="productUnits-'+productNamesIndex+'"></span></td>'
	          +'<td><select id="batchNos-'+productNamesIndex+'" name="batchNos" class="{selected:true}"><option value="-1">-请选择-</option></select></td>'
	          +'<td><s:textfield id="productNums-'+productNamesIndex+'" name="productNums" size="10" cssClass="{required:true,maxlength:10,number:true}"/></td>'
	          +'<td><input type="button" value="删除" class="input1" onclick="deleteProduct(this)" /></td>'
	          +'</tr>');
}

function deleteProduct(button, detailId) {
	if (detailId) {
		var removeDetailIds = $("#order_removeDetailIds").val();
		$("#order_removeDetailIds").val(removeDetailIds + "," + detailId);
	}
	$(button).parents("tr").remove();
}

function initBatchNoSelect(selectId, materialsId) {
	$("#" + selectId).fillOptions(
		"queryMaterialsBatchInfoJOSN.action?materialsId=" + materialsId,
		{datatype:"json",text:"batchNo",value:"batchNo",jsonData:"batchInfoList"});
}

function openSelectDialog(id) {
 	alertDialog(700, 500, "showSelectMaterialsDialog.action", 
 	function (result) {
 		var materials = result.materials;
 		if (materials) {
 			var fieldNames = "";
 			var skuId = result.skuId;
 		   	var skuConfig = materials.skuDetails;
 		   	var acceptNumber = 0;
 	 	   	for (var i in skuConfig) {
 	 	 	   	var config = skuConfig[i];
 	 	 	   	if (config.id == skuId) {
 	 	 	   		acceptNumber = config.number;
 	 	 	 	 	for (var j in config.fields) {
 	  	   				var field = config.fields[j];
 	  	   				fieldNames += field.customName + " ";
 	 	 	 	 	}
 	 	 	 	 	break;
 	 	 	   	}
 	 	   	}
 	 	   	$("#productCodes-" + id).val(materials.code);
 	 	    $("#productIds-" + id).val(skuId);
 			$("#productRootCategorys-" + id).html(materials.rootCategory.name);
 			$("#rootCategoryNames-" + id).val(materials.rootCategory.name);
 			$("#productCategorys-" + id).html(materials.category.name);
 			$("#categoryNames-" + id).val(materials.category.name);
 			$("#productNames-" + id).html(materials.name);
 			$("#productTypes-" + id).html(materials.type);
 			$("#productSkuNames-" + id).html(fieldNames);
 			$("#productSkus-" + id).val(fieldNames);
 			$("#productUnits-" + id).html(materials.units);
 			initBatchNoSelect("batchNos-" + id, skuId);
 		}
 	});
}

$(document).ready(function() {
	$("#saveInStoreVoucher").validate();
});
</script>
</HEAD>
<BODY>
    <s:form action="saveInStoreVoucher">
    <s:hidden name="voucher.id" />
    <s:hidden id="order_removeDetailIds" name="voucher.removeDetailIds" />
    <div class="subnav" align="left">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="100%" align="left" height="31">&nbsp;<img src="common/images/title-pk.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt1">生产计划</span>
			&nbsp;<img src="common/images/leftico2.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt2">编辑入库单</span></td>
		  </tr>
		</table>
      </div>
     <div class="main_1">
       <table width="99%" border="0" cellpadding="5" cellspacing="1" bgcolor="#D3DEEF">
         <tr>
           <td align="left" class="Blue14" bgcolor="#FAFAFA" colspan="2">入库单信息</td>
         </tr>
         <tr>
		    <td width="19%" bgcolor="#FAFAFA" align="right"><strong>送检日期</strong></td>
		    <td width="81%" bgcolor="#FAFAFA">
				<s:textfield name="voucher.createDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true" size="10" cssClass="{required:true}"/>
			</td>
		 </tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>部门</strong></td>
	      <td bgcolor="#FAFAFA">
       	     <s:select name="voucher.deptId"
       	        list="departmentList"
        		listKey="id"
        		listValue="value"
        		headerKey="-1"
        		headerValue="-请选择-"
       	 	    cssClass="{selected:true}" />
			<span class="red-text1">*</span>
		  </td>
		</tr>
		<tr>
	      <td bgcolor="#FAFAFA" align="right"><strong>送检人</strong></td>
	      <td bgcolor="#FAFAFA">
			<s:textfield name="voucher.person" size="10" cssClass="{required:true,maxlength:10}"/>
			<span class="red-text1">*</span>
		  </td>
		</tr>
       </table>
     </div>
     <div class="clear"></div>
	 <div class="main_scroll">
       <table width="960px" cellpadding="0" cellspacing="1" border="0" class="ksglxx2a" id="productList">
        <tr class="ksglxx2bg">
          <th width="60px" >&nbsp;</th>
          <th width="50px" >大分类</th>
          <th width="60px" >中分类</th>
          <th width="95px" >名称</th>
          <th width="180px" >型号</th>
          <th width="180px" >其他</th>
		  <th width="50px">单位</th>
		  <th width="95px">生产批号<span class="red-text1">*</span></th>
		  <th width="95px">送检数量<span class="red-text1">*</span></th>
		  <th align="95px">&nbsp;</th>
		</tr>
	    <s:iterator value="voucher.voucherDetails" id="detail" status="st">
        <tr class="odd">
          <td>&nbsp;<s:hidden id="productCodes-%{#st.index}" name="productCodes" value="%{#detail.productNo}"/>
              <s:hidden id="productIds-%{#st.index}" name="productIds" value="%{#detail.productId}" />
          </td>
          <td><span id='productRootCategorys-<s:property value="#st.index" />'><s:property value="#detail.productRootCategory" /></span>
              <s:hidden id='rootCategoryNames-%{#st.index}' name="rootCategoryNames" value="%{#detail.productRootCategory}" /></td>
          <td><span id='productCategorys-<s:property value="#st.index" />'><s:property value="#detail.productCategory" /></span>
              <s:hidden id='categoryNames-%{#st.index}' name="categoryNames" value="%{#detail.productCategory}" /></td>
          <td><span id='productNames-<s:property value="#st.index" />'><s:property value="#detail.productName" /></span></td>
          <td><span id='productTypes-<s:property value="#st.index" />'><s:property value="#detail.productType" /></span></td>
          <td><span id="productSkuNames-<s:property value="#st.index" />"><s:property value="#detail.productSku" /></span>
              <s:hidden id="productSkus-%{#st.index}" name="productSkus" value="%{#detail.productSku}"/></td>
          <td><span id='productUnits-<s:property value="#st.index" />'><s:property value="#detail.unit" /></span></td>
          <td><span><s:property value="#detail.batchNo" /></span>
    		  <s:hidden id='batchNos-%{#st.index}' name="batchNos" value="%{#detail.batchNo}"/></td>
    	  <td><s:textfield id='productNums-%{#st.index}' name="productNums" value="%{#detail.number}" size="10" 
					cssClass="{required:true,maxlength:10,number:true}"/></td>
          <td>
            <s:hidden name="detailIds" value="%{#detail.id}" />
            <input type="button" value="删除" class="input1" onclick='deleteProduct(this, <s:property value="#detail.id" />)' />
          </td>
	    </tr>
	    </s:iterator>
        <tr>
         <td colspan="3" align="left" valign="top">
           <input type="button" value="添加" class="input1" onclick="addProduct()" />
         </td>
        </tr>
       </table>
      </div>
     <div class="clear"></div>
	 <div class="main_1">
		<table width="98%" border="0" cellpadding="5" cellspacing="0" class="gr-text1">
		   <tr>
			 <td width="45%" align="right">
			   <s:submit value="保存" cssClass="input1" />&nbsp;&nbsp;
			   <input type="button" value="关闭" class="input1" onclick='javascript:window.location.href="inStoreVoucherList.action"' /></td>
			 <td width="55%" align="left"></td>
		   </tr>
	   </table>
	</div>
	<div class="clear"></div>
	</s:form>
</BODY></HTML>
